﻿/// <reference path="../GeneratedArtifacts/viewModel.js" />

myapp.ViewMovement.Details_postRender = function (element, contentItem) {
    contentItem.dataBind("screen.Movement.Id", function (newValue) {
        contentItem.screen.details.displayName = "Movement (" + (newValue == null ? "New" : newValue) + ")";
    });
    contentItem.dataBind("screen.Movement.Amount", function (newValue) {
        contentItem.screen.findContentItem("Rating").isVisible = (newValue != null && newValue != 0);
        ;
    });
};

myapp.ViewMovement.DeepLink_postRender = function (element, contentItem) {
    // The hash is present on non-home screens.  Since we're
    // doing this on the home screen we could skip this part
    // but here it is for completeness.
    var hashPos = window.location.href.indexOf("#");
    if (hashPos >= 0)
        var baseUrl = window.location.href.substr(0, hashPos);
    else
        var baseUrl = window.location.href;
    var fullUrl = baseUrl + "?entity=MMC_Content/Movements(" +
                  contentItem.screen.Movement.Id + ")";
    contentItem.screen.MovementUrl = fullUrl;
};

myapp.ViewMovement.TimeLeft_render = function (element, contentItem) {
    var defaultCountdown = $('#defaultCountdown');
    if (defaultCountdown != null) {
        $(this).remove();
    }
    defaultCountdown = $('<div id="defaultCountdown">Count Down is not started</div>').appendTo($(element));
    RefreshCountDown(contentItem.screen.Movement.DateTo);
};